//
//  mttRotationRecognizer.m
//  mtt
//
//  Created by Gerfried Mikusch on 29.11.10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//


#import "mttRotationRecognizer.h"

@implementation mttRotationRecognizer

@synthesize firstLocation, prevLocation, actLocation;


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	[super touchesBegan:touches withEvent:event];
	
	//Wenn mehr als 1 touch erkannt wurde soll der recognizer fehlschlagen
	if ([touches count] != 1) {
		
		//NSLog(@"too many touches");
		
		self.state = UIGestureRecognizerStateFailed;
		return;
	}
	
	//Startpunkt speichern
	self.firstLocation = [[touches anyObject] locationInView:self.view];
	//NSLog(@"firstLoc x:%f, y:%f", firstLocation.x, firstLocation.y);
	self.state = UIGestureRecognizerStateBegan;
}


-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	[super touchesMoved:touches withEvent:event];
		
	//vorigen Punkt merken
	prevLocation = [[touches anyObject] previousLocationInView:self.view];
	//NSLog(@"prevLoc x:%f, y:%f", prevLocation.x, prevLocation.y);
	
	//aktuellen Punkt merken
	actLocation = [[touches anyObject] locationInView:self.view];
	//NSLog(@"actLoc x:%f, y:%f", actLocation.x, actLocation.y);
	
	self.state = UIGestureRecognizerStateChanged;
	
	
}


-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	[super touchesEnded:touches withEvent:event];
	
	self.state = UIGestureRecognizerStateEnded;
	
	
	
}

-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
	[super touchesCancelled:touches withEvent:event];
	self.state = UIGestureRecognizerStateCancelled;

}

-(void)reset {
	[super reset];
	
	firstLocation = CGPointMake(0, 0);
	prevLocation = CGPointMake(0, 0);
	actLocation = CGPointMake(0, 0);
	
}



@end
